<?php

/**
 * This is the model class for table "user".
 *
 * The followings are the available columns in table 'user':
 * @property integer $id
 * @property string $username
 * @property string $password
 * @property string $roles
 * @property string $last_name
 * @property string $first_name
 * @property string $name_extension
 * @property string $gender
 * @property string $email
 * @property integer $contact_number
 * @property string $specialization
 * @property string $type
 * @property string $clinic_address
 * @property string $website_link
 * @property string $photo
 *
 * The followings are the available model relations:
 * @property SuccessfulCase[] $successfulCases
 * @property Testimony[] $testimonies
 */
class User extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'user';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('username, password, roles, last_name, first_name', 'required'),
			array('contact_number', 'numerical', 'integerOnly'=>true),
			array('username, password, roles, last_name, first_name, email, specialization, type, clinic_address, website_link', 'length', 'max'=>45),
			array('name_extension', 'length', 'max'=>20),
			array('gender', 'length', 'max'=>10),
			array('photo', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, username, password, roles, last_name, first_name, name_extension, gender, email, contact_number, specialization, type, clinic_address, website_link, photo', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'successfulCases' => array(self::HAS_MANY, 'SuccessfulCase', 'user_id'),
			'testimonies' => array(self::HAS_MANY, 'Testimony', 'user_id'),
		);
	}

		const p='practitioner';
    	const np='nonpractitioner';
  //  const a='admin';
	
	
	 public function getOptionRoles(){
        return array(
            self::p=>'Practitioner',
            self::np=>'Non - Practitioner',
      //      self::a=>'Admin',           
        );            
    }
	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'username' => 'Username',
			'password' => 'Password',
			'roles' => 'Roles',
			'last_name' => 'Last Name',
			'first_name' => 'First Name',
			'name_extension' => 'Name Extension',
			'gender' => 'Gender',
			'email' => 'Email',
			'contact_number' => 'Contact Number',
			'specialization' => 'Specialization',
			'type' => 'Type',
			'clinic_address' => 'Clinic Address',
			'website_link' => 'Website Link',
			'photo' => 'Photo',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('roles',$this->roles,true);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('name_extension',$this->name_extension,true);
		$criteria->compare('gender',$this->gender,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('contact_number',$this->contact_number);
		$criteria->compare('specialization',$this->specialization,true);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('clinic_address',$this->clinic_address,true);
		$criteria->compare('website_link',$this->website_link,true);
		$criteria->compare('photo',$this->photo,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}